#include <cstdio>
#define MAX_U 100005
int father[MAX_U];
int rank[MAX_U];

void init(int N) {

	for (int i = 0; i < N; i++)
	{
		father[i] = i;
		rank[i] = 1;
	}
}


int findFather(int x) {

	while (father[x] != x)
	{
		x = father[x];
	}

	return x;
}

int unitGroup(int x, int y) {

	if (x == -1)
	{
		return y;
	}

	int root;
	x = findFather(x);
	y = findFather(y);

	if (x == y)
	{
		return x;
	}

	if (rank[x] < rank[y])
	{
		father[x] = y;
		root = y;
	}
	else
	{
		father[y] = x;
		root = x;
		if (rank[x] == rank[y])
		{
			rank[x]++;
		}
	}

	return root;
}

bool ifGroup(int x, int y) {

	return findFather(x) == findFather(y);

}
int main() {

	int N, M, k, x;
	scanf("%d%d", &N, &M);
	init(N);
	for (int i = 0; i < M; i++)
	{
		scanf("%d", &k);
		int root = -1;
		for (int j = 0; j < k; j++)
		{
			scanf("%d", &x);
			root = unitGroup(root, x);
		}
	}
	int father0 = findFather(0);
	int cunt = 0;
	for (int i = 0; i < N; i++)
	{
		if (findFather(i) == father0)
		{
			cunt++;
		}
	}

	printf("%d", cunt);

	return 0;
}